import router from '@ohos.router'
import { getGoodsDetail } from '../../api/goods'

export default {
    data: {
        goodsDetail: {},
        banners: [],
        widgetsData:[
            {
                icon: '/common/images/ic_shares.png',
                content: 'strings.share'
            },
            {
                icon: '/common/images/ic_favorites.png',
                content: 'strings.favorites'
            },
            {
                icon: '/common/images/ic_price_cut.png',
                content: 'strings.price_reduction_notice'
            }
        ],
        otherList: [
            {
                icon: '/common/images/ic_right.png',
                content: 'strings.free_shipping'
            },
            {
                icon: '/common/images/ic_right.png',
                content: 'strings.store_shipment'
            },
            {
                icon: '/common/images/ic_right.png',
                content: 'strings.return_without_reason'
            }
        ]
    },
    async getGoodsDetailData() {
        const params = router.getParams()
        const res = await getGoodsDetail(params.proid)

        this.goodsDetail = res.data
        this.banners = res.data.banners[0].split(",")
    },
    back() {
        router.back()
    },
    toHomePage() {
        router.replace({
            url: "pages/index/index",
            params: {
                tag: 'home'
            }
        })
    },
    toCartPage() {
        router.replace({
            url: "pages/index/index",
            params: {
                tag: 'cart'
            }
        })
    },
    addToCart() {
      console.log('---addToCart---')
    },
    onInit() {
        this.getGoodsDetailData()
    }
}
